package com.atXiao.food.controller;


import com.atXiao.food.aspect.annotation.LogAspect;
import com.atXiao.food.config.Log;
import com.atXiao.food.constant.BusSignConstant;
import com.atXiao.food.constant.BuscodeConstant;
import com.atXiao.food.reqbody.ReqBody;
import com.atXiao.food.rspbody.RspBody;
import com.atXiao.food.rspbody.category.CategoryItem;
import com.atXiao.food.rspbody.oss.OssRsp;
import com.atXiao.food.rspcode.RspResultCode;
import com.atXiao.food.service.OssService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.validation.Valid;
import java.util.List;

/**
 * @author: lixiaoxiao
 * @date: 2023/11/26 15:57
 * @version: 1.0
 * @desc: 阿里云对象存储
 */
@RestController
@RequestMapping(path = "/oss", produces = MediaType.APPLICATION_JSON_VALUE)
public class OssController {

    public final static Log logger = new Log(OssController.class);


    @Autowired
    OssService ossService;


    /**
     * 阿里云文件上传
     *
     * @param fileType 文件类型  1:图片 2:视频
     * @param file     要上传的文件
     * @return
     */
    @PostMapping(path = "/upload")
    @ResponseBody
    public RspBody<OssRsp> queryCategoryList(String fileType, MultipartFile file) {
        RspBody<OssRsp> rspBody = new RspBody();
        OssRsp ossRsp = new OssRsp();
        try {
            String fileUrl = ossService.uploadFile(fileType, file);
            ossRsp.setFileUrl(fileUrl);
            rspBody.setRetCode(RspResultCode.REQUEST_SUCCESS.getCode());
            rspBody.setRetDesc(RspResultCode.REQUEST_SUCCESS.getDesc());
            rspBody.setRspBody(ossRsp);
        } catch (Exception e) {
            logger.error("", BusSignConstant.TASTE_FOOD, BuscodeConstant.FILE_UPLOAD, e.getMessage(), e);
            rspBody = RspBody.fail(null);
        }
        return rspBody;
    }




}
